import request from "@/utils/request";
import { formatParams } from "@/utils/index";
import store from "@/store";
/**
 * 用户登录接口
 */
export function login({
    phone, email, password, verifyCode,
} = {}) {
    return request({
        url: "/login",
        method: "POST",
        data: {
            phone, email, password, verifyCode,
        },
    });
}
// 获取个人信息
export function userInfo() {
    return request({
        url: "/userInfo",
        method: "GET",
    });
}
// 退出登录
export function logout() {
    return request({
        url: "/logout",
        method: "DELETE",
    });
}
// 获取用户列表
export function getUserList({ page, size }) {
    return request({
        url: "/userList",
        method: "GET",
        params: { page, size },
    });
}
// 获取其他用户信息
export function userInfoById({ id }) {
    return request({
        url: "/userInfo",
        method: "GET",
        params: { uid: id },
    });
}
// 用户相关 - 修改用户信息
export function updateUserInfo(newUserInfo) {
    const columns = ["nickname", "avatar", "gender", "birthday", "desc", "sianweibo", "bilibili", "wechat", "qq"];
    const updateData = formatParams(newUserInfo, columns);
    if (store.getters.nickname === updateData.nickname) {
        delete updateData.nickname;
    }
    return request({
        url: "/userInfo",
        method: "PUT",
        data: updateData,
    });
}

/** @Role */
// 用户角色相关 - 获取角色列表
export function getRoleList() {
    return request({
        url: "/userRoles",
        method: "GET",
    });
}
// 用户角色相关 - 修改角色名
export function editRoleName({ id, role_name }) {
    return request({
        url: `/userRole/${id}`,
        method: "PUT",
        data: { role_name },
    });
}
// 用户角色相关 - 删除角色
export function deleteRole({ id }) {
    return request({
        url: `/userRole/${id}`,
        method: "DELETE",
    });
}
// 用户相关 - 修改帐号绑定接口
export function createRole({ role_name }) {
    return request({
        url: "/userRole",
        method: "POST",
        data: { role_name },
    });
}
// 用户相关 - 修改帐号绑定接口
export function updateAccountBind({ type, sign, verifyCode }) {
    return request({
        url: "/updateAccountBind",
        method: "PUT",
        data: { type, sign, verifyCode },
    });
}
// 找回密码 / 修改密码
export function resetPassword({
    email, phone, verifyCode, newPassword,
}) {
    return request({
        url: "/resetPassword",
        method: "PUT",
        data: {
            email, phone, verifyCode, newPassword,
        },
    });
}
